Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NNVM][FRONTEND][Keras] Support for reusing layers #1192

Merged
merged 5 commits into from
Jun 6, 2018

Conversation

kazum
Copy link
Contributor

@kazum kazum commented May 29, 2018

Moved from dmlc/nnvm#501

@kazum
Copy link
Contributor Author

kazum commented May 29, 2018

@Huyuwei, I updated my codes based on your comment. Can you review this?

@@ -475,7 +475,7 @@ def from_keras(model):
symtab = SymbolTable()
for keras_layer in model.layers:
if isinstance(keras_layer, keras.engine.topology.InputLayer):
keras_layer.name = 'data'
keras_layer.name = keras_layer.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line can be removed

# we append node index to the symbol name to make it unique.
# The one exception is InputLayer. Changing input variable names after conversion
# would confuse users, so we should keep them as far as possible. Fortunately,
# it's safe because all the input layers have unique names in Keras.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are named to input_1, input_2, input_3 ... by default.

if isinstance(pred, keras.engine.topology.InputLayer):
predecessors.append(pred.name)
else:
predecessors.append(pred.name + str(i))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pred.name + '_' +str(i) will be clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds better, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the second thought, I think pred.name + ':' + str(i) will be better since Keras also adds '_[num]' suffixes to layer names.


# With the current implementation, _convert_merge and _convert_concat
# expects their inputs to be List. For now, we handle them differently,
# but in future, we could have a unified way here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazum Keras can't create multiple merge or concat layers from the same name instance, is this correct? Seems this is one assumption here.

Another assumption is keras layers other than merge or concat have only one predecessor. I think this is correct. Can you verify it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazum Keras can't create multiple merge or concat layers from the same name instance, is this correct? Seems this is one assumption here.

I've confirmed it's not correct. I'll add a test case for that and fix the problem.

Another assumption is keras layers other than merge or concat have only one predecessor. I think this is correct. Can you verify it?

Fortunately, looks like the assumption is no longer necessary in the fixed version.

@kazum kazum force-pushed the keras-reuse-layers branch from 70b99ef to 4a548b0 Compare June 1, 2018 14:31
@Huyuwei
Copy link
Contributor

Huyuwei commented Jun 6, 2018

@kazum The new implementation is clean and elegant!

@tqchen tqchen merged commit cf486e3 into apache:master Jun 6, 2018
nishi-t pushed a commit to nishi-t/tvm that referenced this pull request Jun 7, 2018
tqchen pushed a commit to tqchen/tvm that referenced this pull request Jul 6, 2018
sergei-mironov pushed a commit to sergei-mironov/tvm that referenced this pull request Aug 8, 2018
@kazum kazum deleted the keras-reuse-layers branch August 23, 2018 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants